#include <cstdio>

int RemoveDuplicatesFromSortedArray(int* data, int len)
{
	int remove = 0;
	int cur = 0;
	for (size_t i = 1; i < len; i++)
	{
		if (data[cur] != data[i])
		{
			data[++cur] = data[i];
		}
		else
		{
			remove++;
		}
	}
	return remove;
}

int RemoveDuplicatesTwiceFromSortedArray(int* data, int len)
{
	int remove = 0;
	int cur = 0;
	int repeat = 1;
	for (size_t i = 1; i < len; i++)
	{
		if (data[cur] == data[i] && repeat < 2)
		{
			repeat++;
			remove++;
		}
		else
		{
			repeat = 0;
			cur += 2;
			data[cur] = data[i];
		}
	}
	return remove;
}

int main()
{
	int data[]{1, 1, 1, 2, 2, 2, 3, 3, 4};
	int remove = RemoveDuplicatesTwiceFromSortedArray(data, sizeof(data) / sizeof(data[0]));
	printf("remove %d num", remove);
	return 0;
}